package com.example.demo.controller;

import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")

public class MessageController {
//    private List<MessageInfo> messageInfoList = new ArrayList<>();

    @Autowired
    private MessageService messageService;
    @RequestMapping("/publish")

    public boolean publish(@RequestBody MessageInfo messageInfo){
        System.out.println(messageInfo.getMessage());
//        messageInfoList.add(messageInfo);
       messageService.insert(messageInfo);
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageService.query();
    }
}
